﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Coding4Fun.FakeCall.Data;

namespace Coding4Fun.FakeCall.Controls
{
	public partial class LockControl
	{
		public LockControl()
		{
			InitializeComponent();
			IsLocked = true;
		}


		public bool IsLocked { get; set; }

		private void lock_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			if (gridTranslate.Y >= 0)
				return;

			CoastGrid.Stop();
			gridTranslate.Y = e.TotalManipulation.Translation.Y;

			IEasingFunction easing;

			if (e.IsInertial && e.FinalVelocities.LinearVelocity.Y < -1500 ||
				gridTranslate.Y < ActualHeight / -2)
			{
				coastY.Value = -1 * lockScreen.ActualHeight;
				easing = new CircleEase();
				((CircleEase)easing).EasingMode = EasingMode.EaseIn;
				IsLocked = false;
			}
			else
			{
				coastY.Value = 0;
				easing = new BounceEase();
				((BounceEase)easing).EasingMode = EasingMode.EaseOut;
				((BounceEase)easing).Bounces = 2;
				((BounceEase)easing).Bounciness = 5;
			}
			coastY.EasingFunction = easing;
			CoastGrid.Begin();
		}
		
		private void lock_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			e.Handled = true;

			gridTranslate.Y += e.DeltaManipulation.Translation.Y;
			if (gridTranslate.Y > 0)
				gridTranslate.Y = 0;
		}
	}
}
